package com.neuedu.yyzx.common;

import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;

/**
 * @author 金山
 * 项目：yyzx
 * site: https://blog.fulfill.com.cn
 * 描述
 * @data 2025/3/268:50
 */
@Data
public class Ret<T> {


    @Schema(title = "状态")
    private Integer code ;   // 200 400 401 403 500 ....
    
    @Schema(title = "数据")

    private T data; //  200 情况下的  返回数据
    @Schema(title = "错误消息")
    private String msg;


    /**
     * 成功
     * @param data
     * @return
     */
    public static <T> Ret ok(T data){
        Ret ret =  new Ret();
        ret.setCode(200);
        ret.setData(data);
        return  ret;
    }



    //404
    public static Ret notFound(){
        return notFound("url错误");
    }
    public static Ret notFound(String msg){
        Ret ret =  new Ret();
        ret.setCode(404);
        ret.setMsg(msg);
        return  ret;
    }


    //500

    public static Ret error(){
        return error("url错误");
    }
    public static Ret error(String msg){
        Ret ret =  new Ret();
        ret.setCode(500);
        ret.setMsg(msg);
        return  ret;
    }


    public static Ret unauthorized(){
        Ret ret =  new Ret();
        ret.setCode(401);
        ret.setMsg("未授权");
        return  ret;
    }


    public static Ret forbidden(){
        Ret ret =  new Ret();
        ret.setCode(403);
        ret.setMsg("无效的授权");
        return  ret;
    }



}
